#include <iostream>
#include <memory>
using namespace std;




struct AAA
{
	int a1;
	char *p;
	AAA()
	{
		a1 = 1;
	}
};
class myString2
{
public:	
	char *p;
	int len;

	myString2()
	{
		len = 0;
		p = NULL;
	}
	myString2(const char *str)
	{
		len = strlen(str);
		p = (char *)malloc(len + 1);
		memset(p, 0, len + 1);
		memcpy(p, str, len);
	}
};

class hcMemoryPool
{
public:	
	int test2()
	{
		void *vx = malloc(0x1000);
		cout << vx << endl;
	    allocator<myString2> a;
	    //int *ptr=a.allocate(5, (const void *)vx);
		myString2 *ptr = static_cast<myString2*>(vx); 
	    a.construct(ptr, myString2("nihao"));
	    a.construct(ptr+1,myString2());
	    a.construct(ptr+2,myString2());
	    a.construct(ptr+3,myString2());
	    a.construct(ptr+4,myString2());
	    for(int i=0;i<5;i++)
	    {
	        //cout<< ptr[i].p <<"	"<<	&ptr[i] <<  endl;
			printf("%x	:	%s\n", &ptr[i], ptr[i].p);
	        a.destroy(ptr+i);
	    }
	    //a.deallocate(ptr,5);
	    return 0;
	} 

	int test1()
	{
		void *vx = malloc(0x100);
		cout << vx << endl;

	    allocator<int> a;
	    //int *ptr=a.allocate(5, (const void *)vx);
		int *ptr = static_cast<int*>(vx); 
	    a.construct(ptr,3);
	    a.construct(ptr+1,-3);
	    a.construct(ptr+2,3);
	    a.construct(ptr+3,-3);
	    a.construct(ptr+4,3);
	    for(int i=0;i<5;i++)
	    {
	        cout<< ptr[i] <<"	"<<	&ptr[i]<<  endl;
	        a.destroy(ptr+i);
	    }
	    //a.deallocate(ptr,5);

	    return 0;
	} 

};
